package com.jeeplus.test.jlnu.student.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeeplus.test.jlnu.student.domain.entity.BkbsssStudentPrize;
import com.jeeplus.test.jlnu.student.mapper.BkbsssStudentPrizeMapper;
import com.jeeplus.test.jlnu.student.service.BkbsssStudentPrizeService;
import com.jeeplus.test.tools.resp.Convert2Bean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BkbsssStudentPrizeServiceImpl extends ServiceImpl<BkbsssStudentPrizeMapper, BkbsssStudentPrize> implements BkbsssStudentPrizeService {
    @Autowired
    private  BkbsssStudentPrizeMapper bkbsssStudentPrizeMapper;

    @Override
    public BkbsssStudentPrize getBkbsssStudentPrize(String studentId,String flag) {
        LambdaQueryChainWrapper<BkbsssStudentPrize> wrapper = new LambdaQueryChainWrapper<>(bkbsssStudentPrizeMapper);
        wrapper.eq(BkbsssStudentPrize::getStudentId, studentId)
                .eq(BkbsssStudentPrize::getFlag, flag);
        return wrapper.one();
    }

    @Override
    public Boolean bkbsssStudentPrizeUpdate(BkbsssStudentPrize bkbsssStudentPrize) {
        LambdaUpdateChainWrapper<BkbsssStudentPrize> wrapper = new LambdaUpdateChainWrapper<>(bkbsssStudentPrizeMapper);
        if (ObjectUtil.isNotEmpty(bkbsssStudentPrize.getRewardOrPunishment1())){
            wrapper.set(BkbsssStudentPrize::getRewardOrPunishment1,bkbsssStudentPrize.getRewardOrPunishment1());
        }
        if (ObjectUtil.isNotEmpty(bkbsssStudentPrize.getRewardOrPunishment2())){
            wrapper.set(BkbsssStudentPrize::getRewardOrPunishment1,bkbsssStudentPrize.getRewardOrPunishment1());
        }
        if (ObjectUtil.isNotEmpty(bkbsssStudentPrize.getRewardOrPunishment3())){
            wrapper.set(BkbsssStudentPrize::getRewardOrPunishment1,bkbsssStudentPrize.getRewardOrPunishment1());
        }
        if (ObjectUtil.isNotEmpty(bkbsssStudentPrize.getRewardOrPunishment4())){
            wrapper.set(BkbsssStudentPrize::getRewardOrPunishment1,bkbsssStudentPrize.getRewardOrPunishment1());
        }
        if (ObjectUtil.isNotEmpty(bkbsssStudentPrize.getRewardOrPunishment5())){
            wrapper.set(BkbsssStudentPrize::getRewardOrPunishment1,bkbsssStudentPrize.getRewardOrPunishment1());
        }
        //根据id修改
        wrapper.eq(BkbsssStudentPrize::getId, bkbsssStudentPrize.getId());
        return wrapper.update();
    }
}
